<template>
  <div class="body-container layout-padding">
    <el-form label-width="120px" style="margin-bottom: 10px">
      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="计划名称">
            <el-input v-model="state.sd.title" placeholder="计划名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-button size="default" type="primary" class="ml5" @click="searchPlan">
            <el-icon><ele-Search /></el-icon>查询
          </el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="state.planObj.list" border style="width: 100%">
      <el-table-column label="计划名称" prop="title"></el-table-column>
      <el-table-column label="盘点周期" prop="zqName"></el-table-column>
      <el-table-column label="盘点类型" prop="pdlxName"></el-table-column>
      <el-table-column label="业务类型" prop="ywlxName"></el-table-column>
      <el-table-column label="状态" prop="statusName"></el-table-column>
      <el-table-column label="创建人" prop="createuser"></el-table-column>
      <el-table-column label="创建时间">
        <template v-slot="scope">
          <DateFormat :value="scope.row.createtime" :format="'YYYY-MM-DD HH:mm'" v-if="scope.row.createtime"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button size="small" type="primary" @click="viewPlan(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="mt15" background layout="total,sizes, prev, pager, next"
                   @current-change="loadPlan" @size-change="loadPlan" :total="state.planObj.total"
                   v-model:current-page="state.sd.pageNum" v-model:page-size="state.sd.pageSize" :page-sizes="state.sd.pageSizes">
    </el-pagination>
    <el-dialog :title="state.viewForm.title" v-model="state.viewForm.visible" :close-on-click-modal="false" width="960px">
      <ViewPlan v-if="state.viewForm.visible" :planId="state.viewForm.id" :key="state.viewForm.key"></ViewPlan>
    </el-dialog>
  </div>
</template>

<script setup name="planIndex">
import request from '/@/utils/request';
import { ElMessage } from 'element-plus';
import other from '/@/utils/other';
import {reactive, ref, onMounted, onUnmounted, defineAsyncComponent} from "vue";
const ViewPlan = defineAsyncComponent(() => import('/@/views/kucun/plan/viewplan.vue'));

const state = reactive({
  sd: {
    pageNum: 1,
    pageSize: 10,
    pageSizes: [10, 15, 20, 30],
    title:'',
  },
  viewForm :{
    visible : false,
    title:'查看盘点计划',
    key : '',
    id : 0
  },
  planObj:{}
})
const searchPlan = ()=>{
  state.sd.pageNum = 1;
  loadPlan();
}
const loadPlan = ()=>{
  request({
    url: '/plan/pageuserplan',
    data: state.sd
  }).then(res => {
    const { data } = res
    state.planObj = data
  })
}
const viewPlan = (id)=>{
  state.viewForm.visible = true
  state.viewForm.key = other.uuid();
  state.viewForm.id = id;
}
onMounted(()=>{
  loadPlan();
})
onUnmounted(()=>{

})
</script>

<style scoped>

</style>
